#include "NotebookApp.h"
#include "ui_NotebookApp.h"

#include <QDateTime>

#include "DBService.h"

NotebookApp::NotebookApp(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::NotebookApp)
{
    ui->setupUi(this);

    testDB();
}

NotebookApp::~NotebookApp()
{
    DBService::getInstance()->releaseInstance();
    delete ui;
}

void NotebookApp::testDB()
{
    // 定义表结构
    QJsonObject tableAttr;
    tableAttr["time"] = "TEXT PRIMARY KEY";
    tableAttr["topic"] = "TEXT";
    tableAttr["context"] = "TEXT";

    QString tableName = "NotebookTable";

    DBService::getInstance()->connectDatabase();

    //    DBService::getInstance()->createTable(tableName, tableAttr);

    //    // 插入一条数据
    //    QString time = QDateTime::currentDateTime().toString("yy-MM-dd HH:mm:ss");
    //    char topic_str[] = "日志";
    //    char context[] = "今天的工作内容是完成某某功能";
    //    QJsonObject data;
    //    data["time"] = time;
    //    data["topic"] = topic_str;
    //    data["context"] = context;
    //    DBService::getInstance()->insertData(data);

    QJsonObject condition;
    QJsonObject result;

    // 示例：查询过去一个月内的事件
    condition["type"] = DBServicePublic::ONE_MONTH;
    DBService::getInstance()->searchData(condition, result);
    qDebug() << result;

}

